package com.ruoyi.web.controller.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.web.controller.demo.domain.SysMeetroom;
import com.ruoyi.web.controller.mapper.SysMeetManageMapper;
import com.ruoyi.web.controller.demo.domain.SysMeetManage;
import com.ruoyi.web.controller.service.ISysMeetManageService;
import com.ruoyi.common.core.text.Convert;

/**
 * sys_meet_manageService业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-28
 */
@Service
public class SysMeetManageServiceImpl implements ISysMeetManageService 
{
    @Autowired
    private SysMeetManageMapper sysMeetManageMapper;

    /**
     * 查询sys_meet_manage
     * 
     * @param id sys_meet_manage主键
     * @return sys_meet_manage
     */
    @Override
    public SysMeetManage selectSysMeetManageById(Long id)
    {
        return sysMeetManageMapper.selectSysMeetManageById(id);
    }

    @Override
    public List<SysMeetManage> selectByLocal(SysMeetManage sysMeetManage) {
        return sysMeetManageMapper.selectByLocal(sysMeetManage);
    }

    @Override
    public int openById(Long id) {
        return sysMeetManageMapper.openById(id);
    }

    @Override
    public int endById(Long id) {
        return sysMeetManageMapper.endById(id);
    }

    @Override
    public int saveNoteById(SysMeetManage sysMeetManage) {
        return sysMeetManageMapper.saveNoteById(sysMeetManage);
    }

    /**
     * 查询sys_meet_manage列表
     * 
     * @param sysMeetManage sys_meet_manage
     * @return sys_meet_manage
     */
    @Override
    public List<SysMeetManage> selectSysMeetManageList(SysMeetManage sysMeetManage)
    {
        return sysMeetManageMapper.selectSysMeetManageList(sysMeetManage);
    }

    /**
     * 新增sys_meet_manage
     * 
     * @param sysMeetManage sys_meet_manage
     * @return 结果
     */
    @Transactional
    @Override
    public int insertSysMeetManage(SysMeetManage sysMeetManage)
    {
        sysMeetManage.setCreateTime(DateUtils.getNowDate());
        int rows = sysMeetManageMapper.insertSysMeetManage(sysMeetManage);
        insertSysMeetroom(sysMeetManage);
        return rows;
    }

    /**
     * 修改sys_meet_manage
     * 
     * @param sysMeetManage sys_meet_manage
     * @return 结果
     */
    @Transactional
    @Override
    public int updateSysMeetManage(SysMeetManage sysMeetManage)
    {
//        sysMeetManageMapper.deleteSysMeetroomById(sysMeetManage.getId());
        insertSysMeetroom(sysMeetManage);
        return sysMeetManageMapper.updateSysMeetManage(sysMeetManage);
    }

    /**
     * 批量删除sys_meet_manage
     * 
     * @param ids 需要删除的sys_meet_manage主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysMeetManageByIds(String ids)
    {
//        sysMeetManageMapper.deleteSysMeetroomByIds(Convert.toStrArray(ids));
        return sysMeetManageMapper.deleteSysMeetManageByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除sys_meet_manage信息
     * 
     * @param id sys_meet_manage主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteSysMeetManageById(Long id)
    {
//        sysMeetManageMapper.deleteSysMeetroomById(id);
        return sysMeetManageMapper.deleteSysMeetManageById(id);
    }

    /**
     * 新增sys_meet_room信息
     * 
     * @param sysMeetManage sys_meet_manage对象
     */
    public void insertSysMeetroom(SysMeetManage sysMeetManage)
    {
        List<SysMeetroom> sysMeetroomList = sysMeetManage.getSysMeetroomList();
        Long id = sysMeetManage.getId();
        if (StringUtils.isNotNull(sysMeetroomList))
        {
            List<SysMeetroom> list = new ArrayList<SysMeetroom>();
            for (SysMeetroom sysMeetroom : sysMeetroomList)
            {
                sysMeetroom.setId(id);
                list.add(sysMeetroom);
            }
            if (list.size() > 0)
            {
                sysMeetManageMapper.batchSysMeetroom(list);
            }
        }
    }
}
